from flask import request, jsonify

from info.models import AdminUser

# 验证登录状态
def check_login(func):
    def wrapper(*args,**kwargs):
        aid = request.session.get("aid")
        admin = AdminUser.query.filter(AdminUser.id==aid).first()
        if admin:
            return func(*args,**kwargs)
        else:
            return jsonify({"msg":"notlogin"})
    return wrapper

# 验证权限
def check_score(admin,rel_court):
    if admin.court.score == 1:
        return True
    if admin.court == rel_court:
        return True
    if rel_court in admin.court.childs:
        return True
    return False